package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bfc.service.FiscService;
import org.dom4j.Element;

/**
 * 化解国库接口
 *
 * @auther dinggaofei
 * @Date 2023/2/6 11:16
 */
public class PayFiscApi implements ApiHandle {

    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getPayFisc")) { // 获取划解国库票据
            String billNum = body.elementText("billnum");
            if (billNum == null || billNum.length() == 0)
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");
            FiscService fiscService = (FiscService) SpringContextUtil.getBean("fiscService");
         return  fiscService.getPayFisc(billNum);
        } else if (head.equals("setFiscPayInfo")) {// 划解国库缴费信息
            String billnum = body.elementText("billnum");
            String paybankdt = body.elementText("paybankdt");
            String bankaffirm = body.elementText("bankaffirm");
            String bankstation = body.elementText("bankstation");
            FiscService fiscService = (FiscService) SpringContextUtil.getBean("fiscService");
            BaseResult ret = fiscService.setFiscPayInfo(billnum, bankaffirm, paybankdt, bankstation, "00");
            int n = (ret.isSuccess()) ? 1 : 0;
            ret.setData("<returninfo>" + n + "</returninfo>");
            return ret;
        }
        return null;
    }
}
